package com.qbw.app.module.vehicle.holder;

import android.content.Context;
import android.view.ViewGroup;

import com.qbw.app.R;
import com.qbw.app.databinding.VehicleHolderEventSubTypeBinding;
import com.qbw.app.model.EventType;
import com.qbw.app.module.common.holder.CommonHolder;
import com.qbw.core.base.BaseHolder;

/**
 * @author QBW
 * @date 2019/9/3
 */
public class VehicleEventSubTypeHolder extends CommonHolder<EventType.SubEventType,
        VehicleHolderEventSubTypeBinding> {

    public VehicleEventSubTypeHolder(Context context, ViewGroup viewParent, Object listener) {
        super(context, R.layout.vehicle_holder_event_sub_type, viewParent, listener);
    }

    @Override
    public void bindData(int position, EventType.SubEventType data) {
        super.bindData(position, data);
        mBinding.setEvent(data);
        mBinding.executePendingBindings();
        itemView.setOnClickListener(mClickListenerItem);
    }

    @Override
    protected void onClickItem() {
        super.onClickItem();
        mData.setSelected(!mData.isSelected());
        if (mListener instanceof Listener) {
            ((Listener) mListener).onSelectEventSubTypeChanged(mData);
        }
    }

    public interface Listener {
        void onSelectEventSubTypeChanged(EventType.SubEventType type);
    }
}
